<?php
define("_needlogin", "0");
define("_access", "1");
include_once("include/db.config.php"); 

$sql = "SELECT * from team where score!=0 order by score desc,lastsubmit asc";
$r = getAll($sql);

$sql = "SELECT * from challenge where enable=1";
$cc = getAll($sql);
$c = array();
foreach ($cc as $key => $value) {
    $c[$value['id']] = $value;
}


?>
<!DOCTYPE html>
<html>
<?php include("include/head.php"); ?>
<body>
<?php include("include/nav.php"); ?>

<link rel="stylesheet" type="text/css" href="/static/css/c3.min.css">
<style type="text/css">
    .no-return{
        white-space:nowrap;
    }
</style>

<div class="row">
    <br>
    <?php 
        if(!$r){
            echo "<center>暂时无排名信息</center>";
            die();
        }else{
            echo "<h1>积分榜</h1>";
        }
    ?>
    <table id="teamsboard">
        <thead>
            <tr>
                <td><b class="no-return">排名</b></td>
                <td><b class="no-return">队名</b></td>
                <td><b class="no-return">Get Flags !</b></td>
                <td><b class="no-return">总分</b></td>
            </tr>
        </thead>
        <tbody>
            <?php 
            $num = 0;
            foreach ($r as $key => $value) {  ?>
            <tr>
                <td><span><?php echo ++$num;?></span></td>
                <td><span class="no-return"><?php echo $value['name'];?></span></td>
                <td>
            <?php 
                $solvedArr = explode(',', $value['solves']);
                //var_dump($solvedArr);
                foreach ($solvedArr as $s_key => $s_value) {  if($s_key==0) continue; //var_dump($c); ?>
                    <a href="./challenges.php#<?php echo $c[$s_value]['name'];?>" class="no-return">【<?php echo $c[$s_value]['name'];?>】</a>
                <?php } 
                if($value['radio_high']>0){ ?>
                    <a href="javascript:;" class="no-return">【选择题:<?php echo $value['radio_high'];?>】</a>
                <?php } ?>
                </td> 
                <td><span><?php echo $value['score'];?></span></td>       
            </tr>
            <?php } ?>
        </tbody>
    </table>
</div>
        
<?php include("include/script.php"); ?>
</body>
</html>